package cn.hfatec.shms.web.yk.ykTjhd.service;

import java.util.List;
import java.util.HashMap;


import cn.hfatec.shms.web.WeekTime;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.web.yk.ykTjhd.model.YkTjhd;
import cn.hfatec.shms.web.yk.ykTjhd.dao.YkTjhdDao;
import cn.hfatec.shms.web.yk.ykTjhd.model.YkTjhdParams;

import javax.annotation.Resource;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("YkTjhdService")
public class YkTjhdService {

    public static final String BEAN_ID = "YkTjhdService";

    //注入Dao层
    @Resource(name = "YkTjhdDao")
    private YkTjhdDao ykTjhdDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param ykTjhdParams
     * @param page
     *
     */
    @Transactional
    public Table queryYkTjhdTable(YkTjhdParams ykTjhdParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        if (ykTjhdParams.getBillTime() == null && ykTjhdParams.getBillEnd() == null) {

            ykTjhdParams.setBillTime(WeekTime.timeBefore());
            ykTjhdParams.setBillEnd(WeekTime.time());
        }
        params.put("params", ykTjhdParams);
        return baseDao.queryTableByPage("queryYkTjhd", params, page);
    }

    /**
     *
     * 插入数据
     * @param ykTjhd
     *
     */
    @Transactional
    public void saveYkTjhd(YkTjhd ykTjhd) {
        if(ykTjhd.getId() != null) {
            YkTjhd result = getYkTjhd(ykTjhd.getId());
            if(result != null) {
                ykTjhdDao.update(ykTjhd);
            } else {
                ykTjhdDao.insert(ykTjhd);
            }
        } else {
            ykTjhdDao.insert(ykTjhd);
        }
    }

    /**
     *
     * 删除数据
     * @param id
     *
     */
    @Transactional
    public void deleteYkTjhd(Integer id) {

        ykTjhdDao.delete(id);
    }

    /**
     *
     * 删除数据
     * @param ykTjhdList
     *
     */
    @Transactional
    public void deleteYkTjhdBatch(List<String> ykTjhdList) {
        for(String id : ykTjhdList) {
            deleteYkTjhd(Integer.valueOf(id));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param id
     *
     */
    @Transactional
    public YkTjhd getYkTjhd(Integer id) {

        return ykTjhdDao.getYkTjhdById(id);
    }


    /**
     *
     * 根据ID获取数据
     * @param bookId
     *
     */
    @Transactional
    public List getYkTjhdList(String bookId) {

        return ykTjhdDao.getYkTjhdByList(bookId);
    }
}